﻿using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Schema;
using libtcodWrapper;
namespace HDHack
{
    struct MonsterDictionaryItem
    {
        public string name;
        public char icon;
        public int level;
        public int vision;
        public int wealth;
        public int hp;
        public int attack;
        public int defence;
        

        public MonsterDictionaryItem(string nm, char i, int lev, int vis, int wlth, int hps, int atk, int def)
        {
            name = nm;
            icon = i;
            level = lev;
            vision = vis;
            wealth = wlth;
            hp = hps;
            attack = atk;
            defence = def;
        }

    }

    class MonsterDictionary
    {
        //public List<MonsterDictionaryItem> MonsterIndex = new List<MonsterDictionaryItem>();
        public DataTable MonsterIndex;
        TCODRandom rand;

        public MonsterDictionary()
        {
            rand = new TCODRandom((uint)DateTime.Now.Millisecond);
            PopulateMonsterIndex();
        }

        void PopulateMonsterIndex()
        {
            MonsterIndex = new DataTable("Monster");
            MonsterIndex.ReadXmlSchema(".\\HDData\\Monsters\\Monsters.xsd");
            MonsterIndex.ReadXml(".\\HDData\\Monsters\\Monsters.xml");                                    
        }

        public List<Monster> GenerateMonstersForLevel(int level, int MonstersToGet)
        {
            List<Monster> mList = new List<Monster>();
            DataRow[] m = MonsterIndex.Select("level = " + (level + 1));
            
            for (int i = 0; i <= MonstersToGet; i++)
            {
                int rIndex = rnd(0, (m.Length - 1));
                mList.Add(new Monster(Convert.ToChar(m[rIndex]["icon"].ToString()), m[rIndex]["name"].ToString(), (Int16)m[rIndex]["hp"], (Int16)m[rIndex]["attack"], (Int16)m[rIndex]["defence"]));
            }
            return mList;
        }

        int rnd(int min, int max)
        {            
            int r = rand.GetRandomInt(min, max);
            return r;
        }

    }
}
